<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>工种选择</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #app {
            display: flex;
        }

        .wrap {
            display: flex;
            width: auto;
            height: 100vh;
            padding: 0;
            background: #fff;
            line-height: 2rem;
        }

        .item {
            width: 7rem;
            text-align: center;
            padding: .75rem 0;
        }

        .active {
            background: #0689FB;
            color: #fff;
        }

        .close_win {
            flex: 1;
        }

        .ellipsis-1 {
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="wrap">
            <div>
                <template v-for="o,i in parentList">
                  <div class="item ellipsis-1" :class="{active:i===parentSelect}" @click="getChildList(o.work_cate_id,i)">
                      {{o.work_cate_name}}
                  </div>
              </template>
            </div>
            <div>
                <template v-for="o,i in childList">
                  <div class="item ellipsis-1" :class="{active:i===childSelect}" @click="selectWork(o,i)">
                      {{o.work_cate_name}}
                  </div>
              </template>
            </div>
        </div>
        <div class="close_win" onclick="close_f()"></div>
    </div>
</body>
<script src="../../script/api.js" charset="utf-8"></script>
<script src="../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../script/common/common.js" charset="utf-8"></script>
<script src="../../script/common/config.js" charset="utf-8"></script>
<script src="../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();
        vm.init();
    }

    var vm = new Vue({
        el: "#app",
        data: {
            parentList: [],
            childList: [],

            parentSelect: 0,
            childSelect: '',
        },
        methods: {
            init() {
                this.getParentList();
            },
            getParentList() {
                var that = this;
                _ajax(Config.api.WorkCateGetParentList, {}, function(ret) {
                    if (ret.code === 200) {
                        that.parentList = ret.data;
                        that.getChildList(that.parentList[0].work_cate_id, 0);
                    }
                });
            },
            getChildList(parent_id, i) {
                var that = this;
                that.parentSelect = i;
                _ajax(Config.api.WorkCateGetChildList, {
                    parent_id: parent_id
                }, function(ret) {
                    if (ret.code === 200) {
                        that.childList = ret.data;
                    }
                });
            },
            selectWork(o, i) {
                var that = this;
                that.childSelect = i;

                var oParent = JSON.stringify(that.parentList[that.parentSelect]);
                var oChild = JSON.stringify(that.childList[that.childSelect]);

                api.execScript({
                    name: api.pageParam.name,
                    frameName: api.pageParam.frameName,
                    script: 'setWork(' + oParent + ',' + oChild + ')'
                });

                // 关闭页面
                close_f();
            }
        }
    });
</script>

</html>
